-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
self.setText('property "{}:{}"'.format(node.name(), name)) | ||
self.setText(f'property "{node.name()}:{name}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PropertyChangedCmd.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self.setText('lock port "{}"'.format(port.name())) | ||
self.setText(f'lock port "{port.name()}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PortLockedCmd.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self.setText('unlock port "{}"'.format(port.name())) | ||
self.setText(f'unlock port "{port.name()}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PortUnlockedCmd.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self.setText('show port {}'.format(self.port.name())) | ||
self.setText(f'show port {self.port.name()}') | ||
else: | ||
self.setText('hide port {}'.format(self.port.name())) | ||
self.setText(f'hide port {self.port.name()}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PortVisibleCmd.__init__
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
_NodeClass = self.__nodes.get(node_type) | ||
if _NodeClass: | ||
if _NodeClass := self.__nodes.get(node_type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeFactory.create_node_instance
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
for port in node.input_ports() + node.output_ports(): | ||
if port.locked(): | ||
locked_ports.append('{0.node.name}: {0.name}'.format(port)) | ||
|
||
locked_ports.extend( | ||
'{0.node.name}: {0.name}'.format(port) | ||
for port in node.input_ports() + node.output_ports() | ||
if port.locked() | ||
) | ||
base_nodes.append(node) | ||
|
||
if locked_ports: | ||
message = ( | ||
'Selected nodes cannot be extracted because the following ' | ||
'ports are locked:\n{}'.format('\n'.join(sorted(locked_ports))) | ||
) | ||
if prompt_warning: | ||
message = ( | ||
'Selected nodes cannot be extracted because the following ' | ||
'ports are locked:\n{}'.format('\n'.join(sorted(locked_ports))) | ||
) | ||
self._viewer.message_dialog(message, 'Can\'t Extract Nodes') | ||
return | ||
|
||
if push_undo: | ||
self._undo_stack.beginMacro( | ||
'extracted "{}" node(s)'.format(len(nodes)) | ||
) | ||
self._undo_stack.beginMacro(f'extracted "{len(nodes)}" node(s)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.extract_nodes
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Move assignments closer to their usage (
move-assign
) - Replace call to format with f-string (
use-fstring-for-formatting
)
nodes = [] | ||
for item in self._viewer.selected_nodes(): | ||
node = self._model.nodes[item.id] | ||
nodes.append(node) | ||
return nodes | ||
return [self._model.nodes[item.id] for item in self._viewer.selected_nodes()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.selected_nodes
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is only used once (
inline-variable
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
new_name = '{} {}'.format(name, x) | ||
new_name = f'{name} {x}' | ||
if new_name not in node_names: | ||
return new_name | ||
|
||
version = search.group(1) | ||
version = search[1] | ||
name = name[:len(version) * -1].strip() | ||
for x in range(1, len(node_names) + 2): | ||
new_name = '{} {}'.format(name, x) | ||
new_name = f'{name} {x}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.get_unique_name
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
nodes_data.update(node_dict) | ||
nodes_data |= node_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph._serialize
refactored with the following changes:
- Merge dictionary updates via the union operator (
dict-assign-update-to-union
)
node = self._node_factory.create_node_instance(identifier) | ||
if node: | ||
if node := self._node_factory.create_node_instance(identifier): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph._deserialize
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
raise IOError('file does not exist: {}'.format(file_path)) | ||
raise IOError(f'file does not exist: {file_path}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.load_session
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise IOError('file does not exist: {}'.format(file_path)) | ||
raise IOError(f'file does not exist: {file_path}') | ||
|
||
try: | ||
with open(file_path) as data_file: | ||
layout_data = json.load(data_file) | ||
except Exception as e: | ||
layout_data = None | ||
print('Cannot read data from file.\n{}'.format(e)) | ||
print(f'Cannot read data from file.\n{e}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.import_session
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
serial_str = json.dumps(serial_data) | ||
if serial_str: | ||
if serial_str := json.dumps(serial_data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.copy_nodes
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
print('ERROR: Can\'t Decode Clipboard Data:\n' | ||
'"{}"'.format(cb_text)) | ||
print(f"""ERROR: Can\'t Decode Clipboard Data:\n"{cb_text}\"""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.paste_nodes
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
text = '{} ({}) nodes'.format(states[mode], len(nodes)) | ||
text = f'{states[mode]} ({len(nodes)}) nodes' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraph.disable_nodes
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
return '<{}("{}") object at {}>'.format( | ||
self.__class__.__name__, self.name(), hex(id(self))) | ||
return f'<{self.__class__.__name__}("{self.name()}") object at {hex(id(self))}>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraphCommand.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return '<{}(\'{}\') object at {}>'.format( | ||
self.__class__.__name__, self.name, hex(id(self))) | ||
return f"<{self.__class__.__name__}(\'{self.name}\') object at {hex(id(self))}>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PortModel.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return '<{}(\'{}\') object at {}>'.format( | ||
self.__class__.__name__, self.name, self.id) | ||
return f"<{self.__class__.__name__}(\'{self.name}\') object at {self.id}>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise NodePropertyError( | ||
'"{}" reserved for default property.'.format(name)) | ||
raise NodePropertyError(f'"{name}" reserved for default property.') | ||
if name in self._custom_prop.keys(): | ||
raise NodePropertyError( | ||
'"{}" property already exists.'.format(name)) | ||
raise NodePropertyError(f'"{name}" property already exists.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.add_property
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
raise NodePropertyError('No property "{}"'.format(name)) | ||
raise NodePropertyError(f'No property "{name}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.set_property
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
attrs = self._TEMP_property_attrs.get(name) | ||
if attrs: | ||
if attrs := self._TEMP_property_attrs.get(name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.get_tab_name
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
model = self._graph_model | ||
if model: | ||
if model := self._graph_model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.add_port_accept_connection_type
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Unwrap a constant iterable constructor (
unwrap-iterable-construction
)
model = self._graph_model | ||
if model: | ||
if model := self._graph_model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.add_port_reject_connection_type
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Unwrap a constant iterable constructor (
unwrap-iterable-construction
)
connected_ports = model.to_dict['connected_ports'] | ||
if connected_ports: | ||
if connected_ports := model.to_dict['connected_ports']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeModel.to_dict
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
connection_data[accept_ptype] = set([accept_pname]) | ||
connection_data[accept_ptype] = {accept_pname} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodeGraphModel.add_port_accept_connection_type
refactored with the following changes:
- Unwrap a constant iterable constructor (
unwrap-iterable-construction
)
raise ValueError('label "{}" already in use for "{}"' | ||
.format(label, labels[label])) | ||
raise ValueError(f'label "{label}" already in use for "{labels[label]}"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodesPaletteWidget.set_category_label
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
return '<{} object at {}>'.format( | ||
self.__class__.__name__, hex(id(self)) | ||
) | ||
return f'<{self.__class__.__name__} object at {hex(id(self))}>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodesTreeWidget.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
node_ids = ['node:{}'.format(i.toolTip(0)) for i in items] | ||
node_ids = [f'node:{i.toolTip(0)}' for i in items] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodesTreeWidget.mimeData
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
label = '{}'.format(category) | ||
label = f'{category}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function NodesTreeWidget._build_tree
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
self._button.setToolTip( | ||
'rgb: {}\nhex: {}'.format(self._color[:3], hex_color) | ||
) | ||
self._button.setToolTip(f'rgb: {self._color[:3]}\nhex: {hex_color}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PropColorPickerRGB._update_color
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!